package view;

import controler.Controler;
import datenbank.ModelAllgemein;
import datenbank.ModelFormatteile;
import datenbank.ModelStat1;
import datenbank.ModelStat10;
import datenbank.ModelStat11;
import datenbank.ModelStat12;
import datenbank.ModelStat2;
import datenbank.ModelStat3;
import datenbank.ModelStat4;
import datenbank.ModelStat5;
import datenbank.ModelStat6;
import datenbank.ModelStat7;
import datenbank.ModelStat8;
import datenbank.ModelStat9;

import java.awt.CardLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.util.Observable;
import java.util.Observer;

import javax.swing.JPanel;

import model.AnzeigeModel;
import texte.TexteObserver;
import texte.TextePanel;
import view_Status.Status;
import view_handbetrieb.Handbetrieb;

public class Grundbild extends JPanel implements Observer {

	private AnzeigeModel model;
	private Controler contMenue;
	private ModelAllgemein modelAllgemein;
	private ModelFormatteile modelFormatteile;

	private ModelStat1 modelStat1;
	private ModelStat2 modelStat2;
	private ModelStat3 modelStat3;
	private ModelStat4 modelStat4;
	private ModelStat5 modelStat5;
	private ModelStat6 modelStat6;
	private ModelStat7 modelStat7;
	private ModelStat8 modelStat8;
	private ModelStat9 modelStat9;
	private ModelStat10 modelStat10;
	private ModelStat11 modelStat11;
	private ModelStat12 modelStat12;

	private JPanel pnlCardLayout;
	private JPanel pnlHandbetr;
	private JPanel pnlStartseite;
	private JPanel pnlMeldungen;
	private JPanel pnlStatus;
	private JPanel pnlParameter;
	private JPanel pnlStatistik;

	public Grundbild(AnzeigeModel model, ModelFormatteile modelFormatteile, Controler contMenue, ModelAllgemein modelAllgemein,
			ModelStat1 modelStat1, ModelStat2 modelStat2, ModelStat3 modelStat3, ModelStat4 modelStat4, ModelStat5 modelStat5,
			ModelStat6 modelStat6, ModelStat7 modelStat7, ModelStat8 modelStat8, ModelStat9 modelStat9, ModelStat10 modelStat10,
			ModelStat11 modelStat11, ModelStat12 modelStat12) {
		super(new FlowLayout(FlowLayout.LEFT, 10, 10));

		this.model = model;
		this.contMenue = contMenue;

		this.modelAllgemein = modelAllgemein;
		this.modelFormatteile = modelFormatteile;

		this.modelStat1 = modelStat1;
		this.modelStat2 = modelStat2;
		this.modelStat3 = modelStat3;
		this.modelStat4 = modelStat4;
		this.modelStat5 = modelStat5;
		this.modelStat6 = modelStat6;
		this.modelStat7 = modelStat7;
		this.modelStat8 = modelStat8;
		this.modelStat9 = modelStat9;
		this.modelStat10 = modelStat10;
		this.modelStat11 = modelStat11;
		this.modelStat12 = modelStat12;

		this.model.addObserver(this);

		initWidgets();

		addWidgets();
	}

	/**
	 * 
	 */
	private void initWidgets() {
		pnlStartseite = new Startseite(model, contMenue);

		pnlHandbetr = new Handbetrieb(model, contMenue);
		pnlParameter = new Parameter(model, contMenue, modelAllgemein, modelFormatteile, modelStat1, modelStat2, modelStat3,
				modelStat4, modelStat5, modelStat6, modelStat7, modelStat8, modelStat9, modelStat10, modelStat11, modelStat12);

		pnlStatus = new Status(model);

		pnlCardLayout = new JPanel(new CardLayout());
	}

	/**
	 * 
	 */
	private void addWidgets() {
		pnlCardLayout.add(pnlStartseite, TextePanel.STARTSEITE);

		pnlCardLayout.add(pnlParameter, TextePanel.PARAMETER);

		pnlCardLayout.add(pnlHandbetr, TextePanel.HANDBETRIEB);

		pnlCardLayout.add(pnlStatus, TextePanel.STATUS);
		
		add(pnlCardLayout);
	}

	/**
	 * 
	 */
	public void update(Observable o, Object arg) {
		if (model == o) {
			if (arg.equals(TexteObserver.FENSTERCHANGE)) {
				CardLayout cl = (CardLayout) pnlCardLayout.getLayout();
				cl.show(pnlCardLayout, model.getAktivesFenster());
			}
		}
	}
}